package com.memorypalace.deck.biz;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.memorypalace.deck.mapper.NoteTypeMapper;
import com.memorypalace.pojo.CardStyle;
import com.memorypalace.pojo.NoteType;
import com.memorypalace.study.mapper.CardStyleMapper;

@Service("noteTypeBiz")
public class NoteTypeBiz implements INoteTypeBiz {

	@Autowired
	private NoteTypeMapper noteTypeMapper;
	@Autowired
	private CardStyleMapper cardStyleMapper;
	@Override
	public List<NoteType> getNoteTypeByUserId(String userId) {
		return noteTypeMapper.getNoteTypeWithCardStyleByUserId(userId);
	}

	@Override
	public NoteType getNoteTypeByNoteTypeId(String noteTypeId) {
		// TODO Auto-generated method stub
		return noteTypeMapper.getNoteTypeWithCardStyleByNoteTypeId(noteTypeId);
	}

	@Override
	public Boolean editNoteType(NoteType noteType) {
		// TODO Auto-generated method stub
		return noteTypeMapper.editNoteType(noteType);
	}

	@Override
	public Boolean addDefaultNoteType(String userId) {
		// 第1个笔记类型
		NoteType noteType = new NoteType(null, userId, null, "[\"正面\",\"反面\"]", "基础正反");
		noteTypeMapper.addNoteType(noteType);
		// 添加配套的卡片样式
		CardStyle cardStyle1 = new CardStyle(null, noteType.getNoteTypeId(), "正到反", "{{正面}}", "{{正面}}<hr>{{反面}}", ".card { font-family: arial; font-size: 20px; text-align: center; color: black; background-color: white;}",1);
		cardStyleMapper.addCardStyle(cardStyle1);
		CardStyle cardStyle2 = new CardStyle(null, noteType.getNoteTypeId(), "反到正", "{{反面}}", "{{反面}}<hr>{{正面}}", ".card { font-family: arial; font-size: 20px; text-align: center; color: black; background-color: white;}",2);
		cardStyleMapper.addCardStyle(cardStyle2);
		// 第2个笔记类型
		NoteType noteType2 = new NoteType(null, userId, null, "[\"单词\",\"音标\",\"释义\"]", "单词");
		noteTypeMapper.addNoteType(noteType2);
		// 添加配套的卡片样式
		CardStyle cardStyle3 = new CardStyle(null, noteType.getNoteTypeId(), "英译中", "{{单词}}<br>{{音标}}", "{{单词}}<br>{{音标}}<hr>{{释义}}", ".card { font-family: arial; font-size: 20px; text-align: center; color: black; background-color: white;}",1);
		cardStyleMapper.addCardStyle(cardStyle3);
		return null;
	}

}
